#pip install serial xmodem

import serial
from xmodem import XMODEM

ser=serial.Serial("/dev/ttyUSB0",115200,timeout=0.5) 

ser.open()
#ser.write('at+cmgs=13912341234\r\n'.encode())
#s = ser.read(100)
#print (s)

ser.close()

def getc(size, timeout=1):
    return ser.read(size) or None

def putc(data, timeout=1):
    return ser.write(data)

modem = XMODEM(getc, putc)

data = stream.read()
ser.write(data)

stream = open('output', 'wb')
modem.recv(stream)

s = ser.read(1000) 
stream = open('/home/duan//dpsm/fpga/hw/sim/app.srec', 'rb')
modem.send(stream)

s = ser.read(1000)
print (s)  



